package com.dxj.controller;

import com.dxj.request.LoginDTO;
import com.dxj.response.R;
import com.dxj.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author dxj
 * @Description 登录接口
 * @date 2024/7/29 14:50
 */
@RestController
@Api(tags = "登录模块")
public class LoginController {
    private static final Logger logger = LoggerFactory.getLogger(UserController.class);
    @Resource
    private IUserService userService;

    @PostMapping("/login")
    @ApiOperation(value = "用户登录")
    public R login(@RequestBody @Validated LoginDTO loginDTO) {
        logger.info("用户登录接口入参:{}", loginDTO);
        return R.success("操作成功", userService.login(loginDTO));
    }

    @GetMapping("/sysLogout")
    @ApiOperation(value = "用户注销")
    public R logout() {
        logger.info("用户注销");
        userService.removeToken();
        return R.success();
    }
}
